<?php

namespace app\adminapi\controller\v1\exam;

use app\adminapi\controller\AuthController;
use app\exceptions\AdminException;
use app\services\exam\ExamMonitorListService;
use app\utils\Token;
use think\facade\App;

class ExamMonitorList extends AuthController
{

    public function __construct(App $app, ExamMonitorListService $service)
    {
        parent::__construct($app);
        $this->services = $service;
    }

    public function index()
    {
        $where = $this->request->getMore([
            ['website_id', $this->website],
            ['page', 1],
            ['pageSize', 20],

        ]);
        return app()->make('json')->successful($this->services->index($where));
    }

    public function createOrUpdate()
    {
        $where = $this->request->getMore([
            ['id', ''],
            ['admin_id', ''],
            ['name', ''],
            ['exam_id', ''],
            ['user_ids', ''],
            ['website_id', $this->website],
        ]);
        return app()->make('json')->successful($this->services->createOrUpdate($where));
    }

    public function delete()
    {
        $where = $this->request->getMore([
            ['id', ''],
        ]);
        return app()->make('json')->successful($this->services->delete($where));
    }


    /**
     * 通过考试id 查询所有学生
     * @return mixed
     */
    public function getUserFromId()
    {
        $where = $this->request->getMore([
            ['exam_id', ''],
            ['website_id', $this->website],
        ]);
        $jwt = $this->request->header('accessToken');
        if (!Token::verifyToken($jwt)) throw new AdminException('jwt不合法');
        $where['admin_id'] = Token::getUserId($jwt, 'userId');
        return app()->make('json')->successful($this->services->getUserFromId($where));
    }


    /**
     * 查询当前考试人数 和 全部考试人数
     * @return void
     */
    public function examPerson()
    {
        $where = $this->request->getMore([
            ['list', ''], //用于判断是否只需要获取考试学生列表
            ['exam_id', ''],
            ['website_id', $this->website],
        ]);
        return app()->make('json')->successful($this->services->examPerson($where));

    }

    /**
     * 获取当前考试批次的异常人员名单
     * @return void
     */
    public function getExamTryRoll(){
        $where = $this->request->getMore([
            ['exam_id', ''],
            ['idcard', ''],
            ['website_id', $this->website],
        ]);
        return app()->make('json')->successful($this->services->getExamTryRoll($where));

    }






}